clear all
//This do file produces the summary statistics reports in Online Appendix Table A3
cd "______"

log using "log_local_official_unique_identifiers.log"
use "PM10_locoff_befandaft_merge.dta", clear


gen oname1=name
gen obirthprovince1=birthprovince
gen obirthday1=birthday
gen oyearsinpos1=year-floor(posstart/100)
gen  oftkey1=(edu_ft_key1==1|edu_ft_key2==1)
gen oname2=mayor_name
gen obirthprovince2=mayor_birthprovince
gen obirthday2=mayor_birthday
gen oyearsinpos2=year-floor(mayor_posstart/100)
gen oftkey2=(mayor_edu_ft_key1==1|mayor_edu_ft_key2==1)

reshape long oname obirthday obirthprovince oftkey oyearsinpos, i(id year) j(sec)
egen idn=group(oname)
egen idnb=group(oname obirthday)
egen idnbf=group(oname obirthday oftkey)

sum idn idnb idnbf


collapse (max) oyearsinpos, by(idn id sec)

//Panel A
tabstat oyearsinpos,  by(sec) statistics(count mean sd min max) save
return list
matrix Tenure1=r(Stat1)'
matrix Tenure2=r(Stat2)'
matrix Tenuretotal=r(StatTotal)'
putexcel set Tenure_Sec_Stats, replace
putexcel A2=matrix(Tenure1),rownames
putexcel A6=matrix(Tenure2),rownames
putexcel A12=matrix(Tenuretotal),rownames

sort idn

by idn: egen countidn=count(oyearsinpos)

sort idn id
by idn id: egen countidncity=count(oyearsinpos)
gen countidncity2=(countidncity==2)


tabstat countidncity2, statistics(count mean min max) save
return list
matrix RepeatPost=r(StatTotal)'
putexcel set Repeat_Post_Stats, replace
putexcel A2=matrix(RepeatPost),rownames
sort idn id


drop if missing(idn)
collapse (mean) countidn countidncity oyearsinpos sec, by(idn)

gen countidn1=(countidn==1)
gen countidn2=(countidn==2)
gen countidn3=(countidn==3)
gen countidn4=(countidn==4)

//Panels B and C
tabstat countidn* oyearsinpos, statistics(count mean sd min max) save
return list
matrix OfStats=r(StatTotal)'
putexcel set UOfficial_Stats, replace
putexcel A2=matrix(OfStats),rownames


restore




